#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：10.百度翻译.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-20 10:44
'''
import requests


cookies = {
    'BAIDUID': 'B787C22251716E05DB1D518CC305C1C2:FG=1',
    'BDUSS': 'UdMcEFYY0U0eDdxc2hrekZ1MXBGbmJHUWFHVVdvfmRqNC1TeFFyY1NaTTBCeGRuRVFBQUFBJCQAAAAAAAAAAAEAAADlcdUhc3F1ZHZzdDQwOTY4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADR672Y0eu9ma',
    'BDUSS_BFESS': 'UdMcEFYY0U0eDdxc2hrekZ1MXBGbmJHUWFHVVdvfmRqNC1TeFFyY1NaTTBCeGRuRVFBQUFBJCQAAAAAAAAAAAEAAADlcdUhc3F1ZHZzdDQwOTY4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADR672Y0eu9ma',
    'BIDUPSID': 'B787C22251716E05DB1D518CC305C1C2',
    'PSTM': '1728351986',
    'BAIDUID_BFESS': 'B787C22251716E05DB1D518CC305C1C2:FG=1',
    'ZFY': 'MF8Gql6k:APbRf5Mvn:ADz2:Bo:B7nDQ:A7PMVMUIBj6eD08:C',
    'H_WISE_SIDS': '60942_61027_61024_61053_61077_60853_61130_61114_61141',
    'BAIDU_WISE_UID': 'wapp_1731295697694_96',
    'MCITY': '-146%3A',
    'H_WISE_SIDS_BFESS': '60942_61027_61024_61053_61077_60853_61130_61114_61141',
    'RT': '"z=1&dm=baidu.com&si=e9a2558b-c4ee-4b96-a79b-2aabc84a85b9&ss=m3mepf90&sl=2&tt=cfd&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=ema&ul=1b9ai&hd=1b9ar"',
    'BA_HECTOR': '842l2lal2h2l8l84a080a1249tk7n11jjogg11v',
    'H_PS_PSSID': '61027_61053_60853_61130_61114_61141_61198',
    'BDORZ': 'B490B5EBF6F3CD402E515D22BCDA1598',
    'Hm_lvt_afd111fa62852d1f37001d1f980b6800': '1732070518',
    'Hm_lpvt_afd111fa62852d1f37001d1f980b6800': '1732070518',
    'HMACCOUNT': '2192013378312159',
    'Hm_lvt_64ecd82404c51e03dc91cb9e8c025574': '1732070518',
    'Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574': '1732070518',
    'ab_sr': '1.0.1_YzRkNDQ5YzE3YWQ3MmNhYThhYTU5Njg2NWY3ZWZkMTJjNmUzMzIzZWI3YmZhMGU5OWRjYzRmMTRjYTkyYzRmZGY0NzlhNWRiMDQwYTdjOThiZDk2YmMxYWQxYjQ4MTNhZjhiOTYxMTZiMzZlZGVmMDE1MjY0OThjMTI5OTUyMzVjYWIxMjYyODQ0OThlNjU1NjFmNzAxNTVkYTg3MDA3YTY5YjA0NWE0MWE0OTcxNzI0N2Q2M2I1ZDliNTc4Nzg1',
}

headers = {
    'Referer': 'https://fanyi.baidu.com/',
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36 Edg/131.0.0.0',
}

data = {
    'query': 'happy',
    'from': 'en',
    'to': 'zh',
    'token': 'c914a0b09833d0984152dfd60e9a3a85',
    'sign': '221212.492333',
}
url = 'https://fanyi.baidu.com/basetrans'
response = requests.post(url, cookies=cookies, headers=headers, data=data)

print(response.json())
for item in response.json()["trans"]:
    print(item)


result = response.json()["trans"][0]["dst"]
print(result)